package com.fairytask.ui
{
	import com.fairytask.data.Modulator;
	import com.fairytask.engine.components.ToolTips;
	import com.fairytask.engine.components.text.Label;
	import com.fairytask.managers.TipsManage;
	import com.fairytask.resource.StaticIni;
	import com.fairytask.ui.base.FrameUI;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	/**
	 *任务品质积分窗口 
	 * @author pangj
	 * 
	 */
	public class WantedScoreUI extends FrameUI
	{
		private var allScore       :int  = 10;  //任务品质积分完成总次数
		private var _color         :int;        //任务品质颜色
		private var _count         :int;        //任务完成次数
		public var  boxNameLabel   :Label;      //宝箱名称
		public var  completeBar    :MovieClip   //完成进度条
		public var  scoreLabel     :Label;      //积分标签
		public var  boxImg         :MovieClip;  //宝箱图片
		private var isGetPrize     :Boolean = false;//宝箱状态
		private var _model         :Modulator = Modulator.instance;
		/**
		 * 构造方法
		 * @param color  宝箱颜色
		 * @param score  任务完成次数
		 * 
		 */
		public function WantedScoreUI(color:int,count:int,popUI:Boolean=true)
		{
			super(popUI);
			this._color = color;
			this.count = count;
			init();
			boxImg.addEventListener(MouseEvent.CLICK,onGetGood);
			boxImg.addEventListener(MouseEvent.ROLL_OVER,function(evt:MouseEvent):void{
				TipsManage.showTips(StaticIni.getSwfLangStr("BoxColor_"+_color));
			});
			boxImg.addEventListener(MouseEvent.ROLL_OUT,function(evt:MouseEvent):void{
				ToolTips.hide();
			});
		}
		private function init():void
		{
			switch(_color)
			{
				case WantedListUI.TASK_TRAIT_GOLDEN://金色
				{
					boxNameLabel.color   = WantedListUI.BOX_COLOR_GOLDEN;
					boxNameLabel.htmlStr = StaticIni.getSwfLangStr("1000000288");
					//bindManager.BindProp(Player.getInstance().data,"OpenGold",this,"boxState");
					break;
				}
				case WantedListUI.TASK_TRAIT_ORANGE://橙色
				{
					boxNameLabel.color   = WantedListUI.BOX_COLOR_ORANGE;
					boxNameLabel.htmlStr = StaticIni.getSwfLangStr("1000000289");
					//bindManager.BindProp(Player.getInstance().data,"OpenOrange",this,"boxState");
					break;
				}
				case WantedListUI.TASK_TRAIT_PURPLE://紫色
				{
					boxNameLabel.color   = WantedListUI.BOX_COLOR_PURPLE;
					boxNameLabel.htmlStr = StaticIni.getSwfLangStr("1000000290");
					//bindManager.BindProp(Player.getInstance().data,"OpenPurple",this,"boxState");
					break;
				}
			}
		}
		public  function set boxState(val:int):void
		{
			isGetPrize = val == 1;
			setPrizeState(0);
		}
		/**
		 * 设置完成次数
		 * @param count
		 */
		public function set count(count:int):void
		{
			this._count = count;
			scoreLabel.htmlStr = _count+"/"+allScore;
			completeBar.Bar.width = (_count/allScore)*completeBar.BarBg.width;
			setPrizeState(_count == allScore?1:0);
		}
		/**
		 * 点击宝箱，获取物品
		 * 
		 */
		private function onGetGood(evt:MouseEvent):void
		{	
			if(allScore == _count)
			{
				//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_DAILY_TASK_PRIZE,_color);
			}
		}
		/**
		 * 宝箱状态
		 * @param val 0 未开启 1 开启但未领奖 2 已领奖
		 * 
		 */
		public function setPrizeState(val:int):void
		{
			val = isGetPrize ? 2:val;
			switch(val)
			{
				case 0:
					boxImg.gotoAndStop("normal");
					//boxImg.buttonMode	= boxImg.mouseEnabled = false;
					break;
				case 1:
					boxImg.gotoAndStop("flush");
					boxImg.buttonMode	= boxImg.mouseEnabled = true;
					break;
				case 2:
					boxImg.gotoAndStop("unallow");
					boxImg.buttonMode	= boxImg.mouseEnabled = false;
					break;
			}
		}
	}
}